package com.ruoyi.web.controller.TiebaFavorites.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.web.controller.TiebaFavorites.domain.TiebaFavorites;
import com.ruoyi.web.controller.TiebaFavorites.mapper.TiebaFavoritesMapper;
import com.ruoyi.web.controller.TiebaFavorites.service.ITiebaFavoritesService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;

import java.util.List;
import java.util.Map;


/**
 * 分享功能Service业务层处理
 *
 * @author yong
 * @date 2025-03-09
 */
@Service
public class TiebaFavoritesServiceImpl extends ServiceImpl<TiebaFavoritesMapper, TiebaFavorites> implements ITiebaFavoritesService {

    @Autowired
    private TiebaFavoritesMapper tiebaFavoritesMapper;

    /**
     * 查询分享功能列表
     *
     * @param tiebaFavorites 分享功能
     * @return 分享功能
     */
    @Override
    public List<TiebaFavorites> selectTiebaFavoritesList(TiebaFavorites tiebaFavorites) {
        List<TiebaFavorites> tiebaFavoritesList = tiebaFavoritesMapper.selectList(buildQueryWrapper(tiebaFavorites));
        return tiebaFavoritesList;
    }


    private LambdaQueryWrapper<TiebaFavorites> buildQueryWrapper(TiebaFavorites query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<TiebaFavorites> lqw = Wrappers.lambdaQuery();
        lqw.eq(query.getUserId() != null, TiebaFavorites::getUserId, query.getUserId());
        lqw.eq(query.getPostId() != null, TiebaFavorites::getPostId, query.getPostId());
        lqw.eq(query.getDeptId() != null, TiebaFavorites::getDeptId, query.getDeptId());
        lqw.eq(TiebaFavorites::getStatus, 1);
        lqw.orderByDesc(TiebaFavorites::getCreateTime);
        return lqw;
    }

}
